package com.tangzhe.demo03.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * JDK的动态代理
 */
public class Test01InvocationHandler implements InvocationHandler {

    //代理目标
    private Object target;

    public Test01InvocationHandler() {}

    public Test01InvocationHandler(Object target) {
        this.target = target;
    }

    /**
     * JDK的动态代理，模拟AOP环绕通知
     */
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println(method.getName() + "方法调用前");
        //方法执行
        Object obj = method.invoke(target, args);
        System.out.println(method.getName() + "方法调用后");
        return obj;
    }
}
